{% extends 'base/nav.html' %}
{% load static %}

{% block title %}我的景点 - 旅游舆情监测{% endblock %}

{% block content %}
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <div class="page-header">
                <h2><i class="fa fa-map-marker text-primary"></i> 我创建的景点</h2>
                <p class="text-muted">您创建的所有旅游景点</p>
            </div>

            <!-- 操作按钮 -->
            <div class="row mb-4">
                <div class="col-md-6">
                    <a href="{% url 'users:attraction_create' %}" class="btn btn-primary">
                        <i class="fa fa-plus"></i> 创建新景点
                    </a>
                </div>
                <div class="col-md-6 text-right">
                    <span class="badge badge-info">共 {{ total_count }} 个景点</span>
                </div>
            </div>

            {% if attractions %}
            <div class="table-responsive">
                <table class="table table-striped table-hover">
                    <thead class="thead-dark">
                        <tr>
                            <th>景点名称</th>
                            <th>位置</th>
                            <th>状态</th>
                            <th>热度</th>
                            <th>评论数</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for attraction in attractions %}
                        <tr>
                            <td>
                                <strong>
                                    <a href="{% url 'main:attraction_detail' attraction.pk %}">
                                        {{ attraction.name }}
                                    </a>
                                </strong>
                            </td>
                            <td>{{ attraction.city }}, {{ attraction.province }}</td>
                            <td>
                                {% if attraction.status == 'published' %}
                                    <span class="badge badge-success">已发布</span>
                                {% elif attraction.status == 'draft' %}
                                    <span class="badge badge-secondary">草稿</span>
                                {% elif attraction.status == 'pending' %}
                                    <span class="badge badge-warning">待审核</span>
                                {% else %}
                                    <span class="badge badge-danger">已驳回</span>
                                {% endif %}
                            </td>
                            <td>
                                <span class="badge badge-info">
                                    <i class="fa fa-fire"></i> {{ attraction.heat_index }}
                                </span>
                            </td>
                            <td>
                                <span class="badge badge-primary">
                                    <i class="fa fa-comment"></i> {{ attraction.review_count }}
                                </span>
                            </td>
                            <td>{{ attraction.created_at|date:"Y-m-d" }}</td>
                            <td>
                                <div class="btn-group btn-group-sm">
                                    <a href="{% url 'main:attraction_detail' attraction.pk %}"
                                       class="btn btn-outline-info" title="查看">
                                        <i class="fa fa-eye"></i>
                                    </a>
                                    <a href="{% url 'users:attraction_update' attraction.pk %}"
                                       class="btn btn-outline-primary" title="编辑">
                                        <i class="fa fa-edit"></i>
                                    </a>
                                    <a href="{% url 'users:attraction_delete' attraction.pk %}"
                                       class="btn btn-outline-danger" title="删除">
                                        <i class="fa fa-trash"></i>
                                    </a>
                                </div>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>

            <!-- 分页 -->
            {% if is_paginated %}
            <div class="text-center mt-4">
                <nav>
                    <ul class="pagination">
                        {% if page_obj.has_previous %}
                        <li class="page-item">
                            <a class="page-link" href="?page={{ page_obj.previous_page_number }}">上一页</a>
                        </li>
                        {% endif %}

                        {% for num in page_obj.paginator.page_range %}
                        <li class="page-item {% if page_obj.number == num %}active{% endif %}">
                            <a class="page-link" href="?page={{ num }}">{{ num }}</a>
                        </li>
                        {% endfor %}

                        {% if page_obj.has_next %}
                        <li class="page-item">
                            <a class="page-link" href="?page={{ page_obj.next_page_number }}">下一页</a>
                        </li>
                        {% endif %}
                    </ul>
                </nav>
            </div>
            {% endif %}

            {% else %}
            <div class="text-center py-5">
                <i class="fa fa-map-marker fa-5x text-muted mb-3"></i>
                <h4 class="text-muted">暂无创建的景点</h4>
                <p class="text-muted">您还没有创建任何旅游景点</p>
                <a href="{% url 'users:attraction_create' %}" class="btn btn-primary btn-lg">
                    <i class="fa fa-plus"></i> 创建第一个景点
                </a>
            </div>
            {% endif %}
        </div>
    </div>
</div>

<style>
.table th {
    border-top: none;
    font-weight: 600;
}

.btn-group-sm > .btn {
    padding: 0.25rem 0.5rem;
}
</style>
{% endblock %}